package com.lenovo.leos.letools;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import com.lenovo.leos.letools.db.FileDownloadService;
import com.lenovo.leos.letools.db.FileDownloadEntity;

import android.test.AndroidTestCase;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

public class TestFileDownloadService extends AndroidTestCase{

	public void testSave(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		fs.save("www.sohu.com",3333,"",null,null);
	}
	public void testUpdate(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		fs.update("www.sina.com",1);
	}
	public void testGetByUrlpath(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		int len = fs.getData("www.sina.com");
		Log.i("aaa","============"+len);
	}
	
	public void testGetAll(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		List<FileDownloadEntity> fles;
		fles = fs.getAll();
		for(FileDownloadEntity fle : fles){
			Log.i("aaa","========"+fle.toString());
			Log.i("fff","========="+fle.getTopDirid()+"---");
			Log.i("fff","========="+(fle.getTopDirid()==null)+"---");
		}
	}
	
	public void testDel(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		fs.deleteFile("www.sina.com");
		Log.i("aaa","==========success==");
	}
	public void testGetAllFileByDir(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		Map<String,List<FileDownloadEntity>> dirTasks = fs.getAllFileGroupByDir();
		Set<Entry<String, List<FileDownloadEntity>>> entrys = dirTasks.entrySet();
		for(Entry<String,List<FileDownloadEntity>> entry : entrys){
			String dirid = entry.getKey();
			int currentTotalLen=0;
			int totalFileLen=0;
			for(FileDownloadEntity fde : entry.getValue()){
				currentTotalLen +=fde.getDownlength();
				totalFileLen+=fde.getFilelen();
				Log.i("aaa","==========key="+dirid+" : value="+fde);
			}
		}
	}
		
	
	
	public void testupdateIsOver(){
		FileDownloadService fs = new FileDownloadService(this.getContext());
		fs.updateIsOver("1300190792312206019",100);
	}
	
}
